﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SoccerSimulator5000
{
    public class Squad
    {
        public List<Footballer> attackers = new List<Footballer>();
        public List<Footballer> midfielders = new List<Footballer>();
        public List<Footballer> defenders = new List<Footballer>();
        public List<Footballer> goalkeeper = new List<Footballer>();
        public List<Footballer> bench = new List<Footballer>();
        public List<Footballer> squad = new List<Footballer>();

        public Squad()
        {
            //GenerateRandomSquad();
        }


        // Part of atempt to solve load-issue
        public void Init()
        {
            GenerateRandomSquad();
        }


        private void GenerateRandomSquad()
        {
            for (int i = 0; i < 18; i++)
            {
                // Generate some footballers and give the team a standard 4-4-2 formation.

                if (i < 4) // Four attackers
                {
                    // Generate random attacker
                    squad.Add(new Footballer("attacker", 25));
                    if (i == 0 || i == 1)
                    {
                        attackers.Add(squad[i]);
                    }
                    else
                        bench.Add(squad[i]);
                }
                else if (i >= 4 && i < 10) // Six midfielders
                {
                    // Generate random midfielder
                    squad.Add(new Footballer("midfielder", 25));
                    if (i >= 4 && i < 8)
                    {
                        midfielders.Add(squad[i]);
                    }
                    else
                        bench.Add(squad[i]);
                }
                else if (i >= 10 && i < 16) // Six defenders
                {
                    // Generate random defender
                    squad.Add(new Footballer("defender", 25));
                    if (i >= 10 && i < 14)
                    {
                        defenders.Add(squad[i]);
                    }
                    else
                        bench.Add(squad[i]);
                }
                else if (i >= 16) // two goalkeepers
                {
                    // Generate random Goalkeeper
                    squad.Add(new Footballer("goalkeeper", 25));
                    if (i == 16)
                    {
                        goalkeeper.Add(squad[i]);
                    }
                    else
                        bench.Add(squad[i]);
                }
            }
        }
    }
}
